package ioParation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddParation implements IoParation{
    public void work(BookList bookList){
        System.out.println("正在增加图书中。。。。。");
        //1.判断是否放满
        int currentSize = bookList.getUsedSized();
        BookList  bookList1 = new BookList();
        if(bookList1.getBook().length == currentSize){
            System.out.println("书架已经放满无法继续。。。。");
            return;
        }
        //2.创建书本的变量
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名");
        String name =scanner.nextLine();
        System.out.println("请输入作者名");
        String author = scanner.nextLine();
        System.out.println("请输入类型");
        String type = scanner.nextLine();
        System.out.println("请输入价格");
        int price = scanner.nextInt();
        Book newBook = new Book(name,author,price,type);
        //3.判断书名是否重复
        for (int i = 0; i <currentSize ; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                System.out.println("此书已经被收录在图书馆内");
                return;
            }
        }
        //4.最后插入书籍
       bookList.setBook(currentSize,newBook);
        bookList.setUsedSized(currentSize+1);
        System.out.println("新增图书成功");
    }
}
